home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VELENG10.ZIP / WC.C < prev    next >
C/C++ Source or Header  |  1997-07-27  |  2KB  |  103 lines

  1. // ****************************************************************************
  2. // *                                                                          *
  3. // *                      Velena Source Code V1.0                             *
  4. // *                   Written by Giuliano Bertoletti                         *
  5. // *       Based on the knowledged approach of Louis Victor Allis             *
  6. // *   Copyright (C) 1996-97 by Giuliano Bertoletti & GBE 32241 Software PR   *
  7. // *                                                                          *
  8. // ****************************************************************************
  9.  
  10. // Portable engine version.
  11. // read the README file for further informations.
  12.  
  13. // ==========================================================================
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <time.h>
  19.  
  20. #include "connect4.h"
  21. #include "pnsearch.h"
  22. #include "proto.h"
  23.  
  24. long seed=0;
  25.  
  26. // #define MAGIC_NUM1 ((unsigned int)3440802871L)
  27. // #define MAGIC_NUM2 ((unsigned int)3792808219L)
  28. //
  29. // unsigned long pseudo32(unsigned long *seed)
  30. //   {
  31. //   if(*seed&1) *seed=(*seed>>1)^MAGIC_NUM1;
  32. //   else *seed=(*seed>>1);
  33. //
  34. //   return *seed;
  35. //   }
  36.  
  37.  
  38. /* ========================================================================= */
  39.  
  40. // This section is taken from Numerical Recipes in C in order to implement
  41. // a better random number generator.
  42.  
  43. void randomize()
  44.     {
  45.     seed=time(NULL);
  46.     }
  47.  
  48. #define IA 16807
  49. #define IM 2147483647
  50. #define AM (1.0/IM)
  51. #define IQ 127773
  52. #define IR 2836
  53. #define NTAB 32
  54. #define NDIV (1+(IM-1)/NTAB)
  55. #define EPS 1.2e-7
  56. #define RNMX (1.0-EPS)
  57. #define MASK 123459876
  58.  
  59. float ran1(long *idum)
  60. {
  61.     int j;
  62.     long k;
  63.     static long iy=0;
  64.     static long iv[NTAB];
  65.     float temp;
  66.  
  67.     if (*idum <= 0 || !iy) {
  68.         if (-(*idum) < 1) *idum=1;
  69.         else *idum = -(*idum);
  70.         for (j=NTAB+7;j>=0;j--) {
  71.             k=(*idum)/IQ;
  72.             *idum=IA*(*idum-k*IQ)-IR*k;
  73.             if (*idum < 0) *idum += IM;
  74.             if (j < NTAB) iv[j] = *idum;
  75.         }
  76.         iy=iv[0];
  77.     }
  78.     k=(*idum)/IQ;
  79.     *idum=IA*(*idum-k*IQ)-IR*k;
  80.     if (*idum < 0) *idum += IM;
  81.     j=iy/NDIV;
  82.     iy=iv[j];
  83.     iv[j] = *idum;
  84.     if ((temp=AM*iy) > RNMX) return RNMX;
  85.     else return temp;
  86. }
  87. #undef IA
  88. #undef IM
  89. #undef AM
  90. #undef IQ
  91. #undef IR
  92. #undef NTAB
  93. #undef NDIV
  94. #undef EPS
  95. #undef RNMX
  96.  
  97. int my_random(unsigned short maxval)
  98.     {
  99.     return (int)(ran1(&seed)*maxval);
  100.     }
  101.  
  102.  
  103.